<?
    /**
     * PrincipioLab
     *
     * @package    PrincipioLab
     */

    /**
     * PrincipioLab_DateInterval
     *
     * We have to act as a decorator because PHP doesn't let us to change 'days' property manually.
     *
     * @package    PrincipioLab
     */
    class PrincipioLab_DateInterval
    {
        public $y;

        public $m;

        public $d;

        public $h;

        public $i;

        public $s;

        public $days;

        public $invert;

        /**
         * @param DateInterval|string $interval_spec
         */
        public function __construct($interval_spec)
        {
            $date_interval = ($interval_spec instanceof DateInterval) ? $interval_spec : new DateTime($interval_spec);

            $this->y = $date_interval->y;
            $this->m = $date_interval->m;
            $this->d = $date_interval->d;
            $this->h = $date_interval->h;
            $this->i = $date_interval->i;
            $this->s = $date_interval->s;

            $this->days = $date_interval->days;
            $this->invert = $date_interval->invert;
        }


        /**
         * @return int
         */
        public function toSecond()
        {
            return $this->toMinute() * 60 + $this->s * $this->getSign();
        }


        /**
         * @return int
         */
        public function toMinute()
        {
            return $this->toHour() * 60 + $this->i * $this->getSign();
        }



        /**
         * @return int
         */
        public function toHour()
        {
            return $this->toDay() * 24 + $this->h * $this->getSign();
        }


        /**
         * @return int
         */
        public function toDay()
        {
            return $this->days * $this->getSign();
        }


        /**
         * @return int
         */
        public function toMonth()
        {
            return $this->toYear() * 12 + $this->m * $this->getSign();
        }


        /**
         * @return int
         */
        public function toYear()
        {
            return ($this->y) * $this->getSign();
        }


        /**
         * @return int
         */
        public function getSign()
        {
            return ($this->invert == 1 ? -1 : 1);
        }
    }
?>